package com.goods.business.converter;

import com.goods.business.service.InStockService;
import com.goods.common.response.ResponseBean;
import com.goods.common.utils.ListPageUtils;
import com.goods.common.vo.business.InStockVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(value = "入库记录")
@RestController
@RequestMapping("business/inStock/")
public class InStockController {

    @Autowired
    private InStockService inStockService;

    /**
     *  findInStockList?pageNum=1&pageSize=10&status=type=inNum=startTime2021-02-06+22:50:10   endTime   Request Method: GET
     * @param pageNum
     * @param pageSize
     * @param status
     * @param type
     * @param inNum
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation("查询入库记录列表")
    @GetMapping("findInStockList")
    public ResponseBean findInStockList(Integer pageNum, Integer pageSize, Integer status,Integer type,String inNum,String startTime,String endTime){
        List<InStockVO> inStockList =  inStockService.findInStockList(status,type,inNum,startTime,endTime);
        List<InStockVO> page = ListPageUtils.page(inStockList, pageSize, pageNum);
        HashMap<Object, Object> map = new HashMap<>();
        map.put("total", inStockList.size());
        map.put("rows", page);
        return ResponseBean.success(map);
    }

    /*http://www.localhost:8989/business/inStock/detail/112?pageNum=1
Request Method: GET*/

    @ApiOperation("查询单一记录明细")
    @GetMapping("detail/{id}")
    public ResponseBean detail(@PathVariable Long id){
        Map map = inStockService.detail(id);
        return ResponseBean.success(map);
    }

/*
Request URL: http://www.localhost:8989/business/inStock/addIntoStock
    Request Method: POST*/
    @PostMapping("addIntoStock")
    public ResponseBean addIntoStock(@RequestBody InStockVO inStockVO){
        inStockService.addIntoStock(inStockVO);
        return ResponseBean.success();
    }

    //审核通过
   /* Request URL: http://www.localhost:8989/business/inStock/publish/122
    Request Method: PUT*/
    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id){
        inStockService.publish(id);
        return ResponseBean.success();
    }

//    Request URL: http://www.localhost:8989/business/inStock/delete/122
//Request Method: GET
    @GetMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        inStockService.delete(id);
        return ResponseBean.success();
    }

//  还原    Request URL: http://www.localhost:8989/business/inStock/back/111
//Request Method: PUT
    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id){
        inStockService.back(id);
        return ResponseBean.success();
    }
//    移入回收站Request URL: http://www.localhost:8989/business/inStock/remove/127
//Request Method: PUT
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id){
        inStockService.remove(id);
        return ResponseBean.success();
    }

}
